﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace BlueLotus7.ArchiveSystem.Common.Contracts.Sina.Weibo
{
    [DataContract]
    [KnownType(typeof(ArchivedTextArticle))]
    [KnownType(typeof(WeiboUser))]
    public class WeiboArticle : ArchivedTextArticle
    {
        [DataContract]
        public enum WeiboContentType
        {
            [EnumMember]
            Weibo = 0x01,
            [EnumMember]
            WeiboComments = 0x02,
            [EnumMember]
            Both = 0x01 | 0x02,
        }

        [DataMember]
        public int ForwardQuantity
        {
            get;
            set;
        }

        [DataMember]
        public int CommentsQuantity
        {
            get;
            set;
        }

        [DataMember]
        public List<WeiboArticle> Comments
        {
            get;
            set;
        }

        [DataMember]
        public Guid? ForwardFrom
        {
            get;
            set;
        }

        [DataMember]
        public Guid? CommentFor
        {
            get;
            set;
        }

        [DataMember]
        public Guid? Original
        {
            get;
            set;
        }

        [DataMember]
        public List<Guid> PersonKeysInvolved
        {
            get;
            set;
        }

        [DataMember]
        public List<WeiboUser> PersonsInvolved
        {
            get;
            set;
        }

        [DataMember]
        public WeiboContentType ContentType
        {
            get;
            set;
        }

        [DataMember]
        public string Agent
        {
            get;
            set;
        }

        public WeiboArticle()
            : base()
        {
            this.PersonKeysInvolved = new List<Guid>();
        }

        public bool EqualsByKey(WeiboArticle article)
        {
            return article != null && article.Key == this.Key;
        }

        public bool EqualsByIdentity(WeiboArticle article)
        {
            return article != null && !string.IsNullOrWhiteSpace(article.ThirdPartyIdentity) && article.ThirdPartyIdentity == this.ThirdPartyIdentity;
        }
    }
}
